﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Internet_Deliver_Therapy.Models;
using Internet_Deliver_Therapy.Controllers;
using Internet_Deliver_Therapy.Controllers.Patient;

namespace Internet_Deliver_Therapy.Views.Index
{
    public partial class Confirmation : System.Web.UI.Page
    {
        private Users user;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["User"] != null)
            {
                user = (Users)Session["User"];
            }

            lblNRIC.Text = user.Nric;
            lblFirstName.Text = user.FirstName;
            lblLastName.Text = user.LastName;
            lblRace.Text = user.Race;
            lblEmail.Text = user.Email;
            lblMobileNo.Text = user.MobileNo;
            lblHomeNo.Text = user.HomeNo;
            lblGender.Text = user.Gender.ToString();
            string [] dobString = user.Dob.ToString().Split(' ');
            lblDOB.Text = dobString[0];
            lblNotifyVia.Text = user.NotifyVia;
            
            string newsletter = "No";
            if (user.Newsletter == 'T')
            {
                newsletter = "Yes";
            }

            lblNewsletter.Text = newsletter;

        }

        //Encrypt password
        protected void Register_Click(object sender, EventArgs e)
        {
            
            UsersController userController = new UsersController();
            PatientController patientController = new PatientController();

            bool registered = userController.createUsers(user);
            
            if (registered == true)
            {
                bool deleted = patientController.removePatientFromWaitingList(user.Nric.ToString());

                if (deleted == true)
                {
                    Response.Redirect("Login.aspx");
                }            }
        }
    }
}